// ---------------------------------------------- //
// Sonic CD Scrapped Rounds: R2 Rotate Platform 2 //
// Author: Christian Whitehead 'The Taxman'       //
// ---------------------------------------------- //

//-------Aliases-------//
#alias Object.Value0	:	Object.Angle
#alias Object.Value1	:	Object.XDrawPos
#alias Object.Value2	:	Object.YDrawPos
#alias Object.Value3	:	Object.XVelocity
#alias Object.Value4	:	Object.YVelocity
#alias Object.Value5	:	Object.SwingAngle
#alias Object.Value6	:	Object.AngleSaver

#alias Object.PropertyValue	:	Object.ChainLength
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod

// Time Period Aliases
#alias 0	:	TIME_PRESENT
#alias 1	:	TIME_PAST
#alias 2	:	TIME_GOOD_FUTURE
#alias 3	:	TIME_BAD_FUTURE
#alias 4	:	TIME_CORRUPTED_PRESENT
#alias 5 	: 	TIME_FURTHER_PAST
//-------Aliases-------//



sub ObjectMain
	if Object.State == 0
		Object.Angle = 170
		Object.State++
	end if

	Object.Angle += 1
	Object.Angle &= 511
	Object.Value6 = Object.Angle
end sub

sub ObjectPlayerInteraction
	
	TempValue3 = 0
	while TempValue3 < 1
	TempValue1 = Object.PropertyValue
	TempValue1++
	TempValue1 <<= 4
	Cos(Object.XVelocity, Object.Angle)
	Object.XVelocity  *= TempValue1
	Object.XVelocity <<= 7
	Object.XVelocity  += Object.XPos
	Object.XVelocity  &= 0xFFFF0000 // Truncate the value
	Object.XVelocity  -= Object.XDrawPos

	Sin(Object.YVelocity, Object.Angle)
	Object.YVelocity  *= TempValue1
	Object.YVelocity <<= 7
	Object.YVelocity  += Object.YPos
	Object.YVelocity  &= 0xFFFF0000 // Truncate the value
	Object.YVelocity  -= Object.YDrawPos
	
	TempValue0 = Object.XPos
	TempValue1 = Object.YPos

	Object.XPos = Object.XDrawPos
	Object.YPos = Object.YDrawPos

	PlayerObjectCollision(C_PLATFORM, -24, -6, 24, 8)
	if CheckResult == true
		Player.XPos += Object.XVelocity
		Player.YPos += Object.YVelocity
	end if

	Object.XPos = TempValue0
	Object.YPos = TempValue1
			TempValue3++
		loop
end sub


sub ObjectDraw
	TempValue0 = 0
	TempValue1 = 16
	TempValue3 = 0
	while TempValue3 < 1
		while TempValue0 < Object.PropertyValue
			Cos(TempValue2, Object.Angle)
			TempValue2  *= TempValue1
			TempValue2 <<= 7
			TempValue2  += Object.XPos

			Sin(TempValue3, Object.Angle)
			TempValue3  *= TempValue1
			TempValue3 <<= 7
			TempValue3  += Object.YPos

			DrawSpriteXY(1, TempValue2, TempValue3)

			TempValue0++

			TempValue1 += 16
		loop

		Cos(Object.XDrawPos, Object.Angle)
		Object.XDrawPos  *= TempValue1
		Object.XDrawPos <<= 7
		Object.XDrawPos  += Object.XPos
		Object.XDrawPos  &= 0xFFFF0000 // Truncate the value

		Sin(Object.YDrawPos, Object.Angle)
		Object.YDrawPos  *= TempValue1
		Object.YDrawPos <<= 7
		Object.YDrawPos  += Object.YPos
		Object.YDrawPos  &= 0xFFFF0000 // Truncate the value

		DrawSpriteXY(2, Object.XDrawPos, Object.YDrawPos)
			TempValue3++
		loop
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects2.gif")
	TempValue0 = HUD.CurrentTimePeriod
	TempValue1 = 101
	TempValue0 *= 17
	TempValue1 += TempValue0 
	
	SpriteFrame(-8, -8, 16, 16, 230, 52)		// #0 - Connection Joint
	SpriteFrame(-8, -8, 16, 16, 230, 69)		// #1 - Chain
	SpriteFrame(-24, -8, 48, 16, 133, TempValue1)		// #2 - Platform
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	Object.Angle = 0

	DrawSprite(0)

	TempValue0 = 0
	TempValue1 = 16
	while TempValue0 < Object.PropertyValue
		Cos(TempValue2, Object.Angle)
		TempValue2  *= TempValue1
		TempValue2 <<= 7
		TempValue2  += Object.XPos

		Sin(TempValue3, Object.Angle)
		TempValue3  *= TempValue1
		TempValue3 <<= 7
		TempValue3  += Object.YPos

		DrawSpriteXY(1, TempValue2, TempValue3)

		TempValue0++

		TempValue1 += 16
	loop

	Cos(Object.XDrawPos, Object.Angle)
	Object.XDrawPos  *= TempValue1
	Object.XDrawPos <<= 7
	Object.XDrawPos  += Object.XPos
	Object.XDrawPos  &= 0xFFFF0000 // Truncate the value

	Sin(Object.YDrawPos, Object.Angle)
	Object.YDrawPos  *= TempValue1
	Object.YDrawPos <<= 7
	Object.YDrawPos  += Object.YPos
	Object.YDrawPos  &= 0xFFFF0000 // Truncate the value

	DrawSpriteXY(2, Object.XDrawPos, Object.YDrawPos)
end sub


sub RSDKLoad
	LoadSpriteSheet("R1/Objects2.gif")

	SpriteFrame(-8, -8, 16, 16, 173, 230)		// #0 - Connection Joint
	SpriteFrame(-8, -8, 16, 16, 190, 230)		// #1 - Chain
	SpriteFrame(-24, -8, 48, 16, 207, 230)		// #2 - Platform

	SetVariableAlias(ALIAS_VAR_PROPVAL, "length")
end sub
